package core.september.cloudbadge.model.badge;

import javax.persistence.Id;
import javax.persistence.Transient;

import com.google.appengine.api.datastore.Text;
import com.google.gson.Gson;

import ezvcard.VCard;

public abstract class AbsField {
	
	public enum FieldType{
		USERINFO,
		WORK,
		HOME,
		EXTENDED
	}
	
	@Id
	private Long id;
	private boolean userEditable = true;
	
	@Transient
	private VCard vcard;
	private FieldType fType;
	
	@Transient
	private Gson gson = new Gson();
	
	public Long getId() {
		return id;
	}
	
	
	public boolean isUserEditable() {
		return userEditable;
	}
	public void setUserEditable(boolean userEditable) {
		this.userEditable = userEditable;
	}
	
	public VCard getVcard() {
		if(vcard == null) {
			setVcard(new VCard());
		}
		//return gson.fromJson(vcard.getValue(), VCard.class);
		return vcard;
	}
	
	public void setVcard(VCard vcard) {
		//this.vcard = new Text(gson.toJson(vcard));
		this.vcard = vcard;
	}

	public FieldType getfType() {
		return fType;
	}

	public void setfType(FieldType fType) {
		this.fType = fType;
	}
	
	public abstract void commit() ;
	
	
}
